<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String title = "信息综合系统";
%>
<%@ include file="/WEB-INF/jsp/header.jsp"%>
<title><%=title%>-费用申请管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-touch-fullscreen" content="no" />
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-capable" content="no" />
</head>

<body class="fixed-top" style="background: #fff;">
	

	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12" style="border-bottom:0px solid #4A8BC2">
				<ul class="breadcrumb" style="padding-bottom: 12px;background: #fff;">
					<li><a href="${pageContext.request.contextPath}/user/index.do" >
						 <i class="icon-angle-left"></i>
						 <i class="icon-angle-left"></i> &nbsp;&nbsp;
						 首页控制台</a>
						<span class="divider">/</span>
					</li>
					<li class="active">
					费用申请管理
					</li>
					<li class="pull-right search-wrap">
					<button
					 onclick="toggleCondi();" 
					 class="btn dropdown-toggle" data-toggle="dropdown">
								<span id="but_text">隐藏筛选区域</span> <i id="toggleCondi_i" class="icon-angle-up"></i>
					</button>
					&nbsp;&nbsp;
					<div class="btn-group pull-right">
						<button class="btn dropdown-toggle" data-toggle="dropdown">
							更多 <i class="icon-angle-down"></i>
						</button>
						<ul class="dropdown-menu pull-right">
							<li><a
								href="${pageContext.request.contextPath}/cost/download.do">下载已筛选的费用申请</a></li>
							     <li><a href="#" onclick="showOpen(0,'新增');">新增一条费用申请</a></li>
							     <li><a href="#" onclick="openUpload('费用管理');">Excel批量上传N条</a></li>
						</ul>
					</div></li>
				</ul>
			</div>
		</div>
		
		<!-- 查询过滤时的表单数据 -->
		<div class="widget">
			<div class="row-fluid">
				<div class="clearfix">
					<form id="filterForm">
					    <input type="hidden" value="${user.age}" id="age" />
						<c:if test="${user.age==0}"><!-- 经理 -->
						   <input type="hidden" value="${user.user_name}" name="mgr" />
						</c:if>
						
					    <select id="status" onMouseOver="this.title='选择状态'" name="status"
                            multiple="multiple" size="1" class="input-medium m-wrap">
                            <c:forEach items="${costStatus}" var="status">
                                <option value="${status}">${status}</option>
                            </c:forEach>   
                        </select> 
                        <select id="costType" name="costType" multiple="multiple"
                            onMouseOver="this.title='选择状态'"
                            size="1" class="input-medium m-wrap">
                            <option value="开发费用">开发费用</option>
                            <option value="上量费用">上量费用</option>
                            <option value="业务交际费用">业务交际费用</option>
                            <option value="差旅费用">差旅费用</option>
                        </select>
                        <select id="stripLine" name="stripLine" multiple="multiple"
                            onMouseOver="this.title='选择条线'"
                            size="1" class="input-medium m-wrap">
                            <option value="Rx">Rx</option>
                            <option value="OTC">OTC</option>
                        </select>
                        <select id="regulation" name="regulation" size="1" 
                                multiple="multiple" onMouseOver="this.title='选择品规'"
                                class="input-medium m-wrap">
                             <option value="B5">B5</option>
                             <option value="B10">B10</option>
                             <option value="A24">A24</option>
                             <option value="A36">A36</option>
                             <option value="A48">A48</option>
                             <option value="A20">A20</option>
                             <option value="A30">A30</option>
                             <option value="A40">A40</option>
                             <option value="Y24">Y24</option>
                             <option value="Y36">Y36</option>
                             <option value="Y48">Y48</option>
                             <option value="Y20">Y20</option>
                             <option value="Y30">Y30</option>
                             <option value="Y40">Y40</option>
                             <option value="Y60">Y60</option>
                             <option value="Z24">Z24</option>
                             <option value="Z36">Z36</option>
                             <option value="Z48">Z48</option>
                             <option value="Z20">Z20</option>
                             <option value="Z30">Z30</option>
                             <option value="Z40">Z40</option>
                             <option value="Z60">Z60</option>
                         </select>
                         <c:if test="${user.age!=0}"><!-- 经理 -->
                         <input type="text" class="span1 typeahead" name="mgr" id="mgr" ondblclick="clearText('mgr')"
                                            placeholder="填写经理" data-provide="typeahead" data-items="4" />
						</c:if>
                         <input type="text" name="startTime" class="Wdate" id="startTime"
	                            style="width: 120px;" placeholder="请输入开始日期"
	                            onfocus="WdatePicker({isShowClear:true,readOnly:false,dateFmt:'yyyy/MM/dd'})" />
                         <input type="text" name="endTime" class="Wdate" id="endTime"
                                style="width: 120px;" placeholder="请输入结束日期"
                                onfocus="WdatePicker({isShowClear:true,readOnly:false,dateFmt:'yyyy/MM/dd'})" />
						<input type="button" id="seach" name="seach" value="查询"
							class="btn  btn-primary" style="margin-bottom: 10px;"
							onclick="query(pNumber,pSize);"/> 
						<input type="reset" id="reset"
							name="reset" value="重置该页面" class="btn  btn-primary"
							style="margin-bottom: 10px;" onclick="resetf();" />
					</form>
				</div>
			</div>

            <!-- 文件上传 -->
	        <div id="uploadFileForm" hidden>
	            <div class="modal-body" >
	                 <form action="${pageContext.request.contextPath}/cost/daoru.do"
	                    method="post" id="uploadForm" enctype="multipart/form-data">
	                        点击该按钮选择文件:<input type="file" name="excelFile" multiple="multiple"
	                            class="input-medium" id="file"><br/>
	                </form>
	             </div>
	        </div>

			<!-- 新增、更新时的表单数据 -->
			<div id="form_div" hidden>
				<div class="modal-body" style="height: 90%">
					<form method="post" id="submitForm" style="padding-left:10px;">
						<input name="id" id="idU" hidden value="0">
					<table>
					    <c:if test="${user.age==0}"><!-- 经理 -->
                           <input type="hidden" value="${user.user_name}" name="mgr" />
                        </c:if>
                        <c:if test="${user.age>=1}"><!-- 助理 -->
                            <tr>
                               <td>经理 *</td>
                               <td>
                               <input type="text" class="span1 typeahead noNull" name="mgr" id="mgrU" ondblclick="clearText('mgrU')"
                                      data-provide="typeahead" data-items="4" />
                               </td>
                           </tr>
                           <!-- <input type="hidden" value="已OA备案" name="status" /> -->
                        </c:if>
                       	<tr>
                              <td>促销开始日期 *</td>
                               <td>
                                   <!-- <input type="text" name="startTime" class="Wdate noNull" id="startTimeU"
                                       style="width: 120px;" 
                                       onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'endTimeU\')}',lang:'zh-cn',readOnly:false })"/> -->
                                   <input type="text" name="startTime" class="Wdate noNull" id="startTimeU"
                                       style="width: 120px;" 
                                       onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',maxDate:'#F{$dp.$D(\'endTimeU\')}',lang:'zh-cn',readOnly:false })"/>
                              </td>
                           </tr>
                           <tr>
                              <td>促销结束日期 *</td>
                               <td>
                                   <input type="text" name="endTime" class="Wdate noNull" id="endTimeU"
                                       style="width: 120px;"
                                       onfocus="WdatePicker({dateFmt:'yyyy/MM/dd',minDate:'#F{$dp.$D(\'startTimeU\')}',lang:'zh-cn',readOnly:false})"/>
                               </td>
                           </tr>
                           
                           <tr>
                               <td>费用类型*</td>
                               <td>
                                   <select id="costTypeU" name="costType" 
                                        size="1" class="input-medium m-wrap">
                                      <option value="开发-外部费用">开发-外部费用</option> 
                                      <option value="开发-内部费用">开发-内部费用</option> 
                                      <option value="上量-推广费用">上量-推广费用</option> 
                                      <option value="上量-促销费用 ">上量-促销费用</option> 
                                      <option value="差旅-自驾费用">差旅-自驾费用</option> 
                                      <option value="差旅-非自驾费用">差旅-非自驾费用</option> 
                                      <option value="业务交际费用">业务交际费用</option>
                                    </select>
                               </td>
                            </tr>
                            <tr>
                               <td> 申请金额 *</td>
                                <td>
                                    <input type="text" class="input-medium typeahead noNull sz"
                                    name="money" id="moneyU" data-provide="typeahead" placeholder="若为礼品，请折现"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('申请金额只能输入【数字】');this.value='';}"
                                   
                                    data-items="4" />
                                </td>
                            </tr> 
                            <tr>
                               <td> 省份 </td>
                                <td>
                                   <input type="text" class="input-medium typeahead"
                                    name="province" id="provinceU" data-provide="typeahead"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td> 客户 </td>
                                <td>
                                   <input type="text" class="input-medium typeahead"
                                    name="customer" id="customerU" data-provide="typeahead"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>
                                <select style="width:90px;" onchange="changeTC(this.value)" id="tc">
                                    <option value="入货乙方" selected="selected">入货乙方</option>
                                    <option value="区县">区县</option>
                                </select>
                               </td>
                                <td>
                                    <input type="text" class="input-medium typeahead"
                                    name="terminal" id="terminalU" data-provide="typeahead"
                                    data-items="4" placeholder="请输入入货乙方" />
                                    
                                    <input type="text" class="input-medium typeahead"
                                    name="county" id="countyU" data-provide="typeahead" placeholder="请输入区县"
                                    data-items="4"/>
                                </td>
                            </tr>
                            <tr>
                               <td>品规</td>
                                <td>
                                    <select id="regulationU" name="regulation" size="1"
                                        class="input-medium m-wrap">
                                        <option value=""></option>
                                        <option value="A24">A24</option>
                                        <option value="A36">A36</option>
                                        <option value="A48">A48</option>
                                        <option value="A20">A20</option>
                                        <option value="A30">A30</option>
                                        <option value="A40">A40</option>
                                        <option value="Y24">Y24</option>
                                        <option value="Y36">Y36</option>
                                        <option value="Y48">Y48</option>
                                        <option value="Y20">Y20</option>
                                        <option value="Y30">Y30</option>
                                        <option value="Y40">Y40</option>
                                        <option value="Y60">Y60</option>
                                        <option value="Z24">Z24</option>
                                        <option value="Z36">Z36</option>
                                        <option value="Z48">Z48</option>
                                        <option value="Z20">Z20</option>
                                        <option value="Z30">Z30</option>
                                        <option value="Z40">Z40</option>
                                        <option value="Z60">Z60</option>
                                        <option value="B5">B5</option>
                                        <option value="B10">B10</option>
                                    </select>
                                 </td>
                            </tr>
                            <tr>
                               <td>条线 </td>
                                <td>
                                    <select id="stripLineU" name="stripLine"
                                        size="1" class="input-medium m-wrap">
                                        <option value="Rx">Rx</option>
                                        <option value="OTC">OTC</option>
                                    </select>
                                 </td>
                            </tr>
                            <tr>
                               <td>智能匹配</td>
                                <td>
                                <input type="button" value="点我自动完善以下信息"
								class="btn  btn-primary" style="margin-bottom: 10px;"
								onclick="fill();"/> 
							
                                 </td>
                            </tr>
                            <tr>
                               <td>中标价 </td>
                                <td>
                                    <input type="text"
                                     class="input-medium" id="zbPriceU"
                                    name="zbPrice" data-provide="typeahead"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('中标价只能输入【小数】');this.value='';}"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>开票价</td>
                                <td>
                                    <input type="text" class="input-medium typeahead"
                                    name="kpPrice" id="kpPriceU" data-provide="typeahead"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('开票价只能输入【小数】');this.value='';}"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>测算价</td>
                                <td>
                                    <input type="text" class="input-medium typeahead"
                                    name="csPrice" id="csPriceU" data-provide="typeahead"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('测算价只能输入【小数】');this.value='';}"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>返款总费用(1+3+4)</td>
                                <td>
                                    <input type="text" 
                                    placeholder="1推广+3财务+4达标"
                                    class="input-medium typeahead"
                                    name="totalCost" id="totalCostU" data-provide="typeahead"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>返款信息</td>
                                <td>
                                <textarea placeholder="开户人、开户行、账号" class="input-large" rows="3" name="refundsInfo" id="refundsInfoU"></textarea>
                                </td>
                            </tr>
                            
                            <tr>
                               <td>当前月均纯销</td>
                                <td>
                                   <input type="text" class="input-medium typeahead"
                                    name="nowMonthSale" id="nowMonthSaleU"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('当前月均纯销只能输入【整数或者小数】');this.value='';}"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>目标月均纯销</td>
                                <td>
                                    <input type="text" class="input-medium typeahead"
                                    name="aimMonthSale" id="aimMonthSaleU" data-provide="typeahead"
                                    onblur="if(!/^[0-9]+([.]{1}[0-9]+){0,1}$/.test(this.value)){layer.msg('目标月均纯销只能输入【整数或者小数】');this.value='';}"
                                    data-items="4" />
                                </td>
                            </tr>
                            <tr>
                               <td>备注 </td>
                               <td>
                                   <textarea class="input-large" rows="3" name="remark" id="remarkU"></textarea>
                               </td>
                            </tr>
                             <c:if test="${user.age==0}"><!-- 经理 -->
	                           <input type="hidden" value="待审批" name="status" />
	                         </c:if>
	                        <c:if test="${user.age>=1}"><!-- 助理 -->
		                        <tr>
	                               <td>审批状态*</td>
	                               <td>
	                                    <select name="status" class="input-medium m-wrap">
	                                    <c:forEach items="${costStatus}" var="status">
                                             <option value="${status}">${status}</option>
                                         </c:forEach>
	                                    </select>
	                               </td>
	                            </tr>
	                        </c:if>
                            
                        </table>
					</form>
				</div>
			</div>

			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN ALERTS PORTLET-->
					<div class="widget blue">
						<div class="widget-title">
							<h4>
								<i class="icon-reorder"></i>
								<a href="javascript:;" onclick="scrollToLeft();" title="定位到表格最左端" style ="color:white;">最左</a>
				                <a href="javascript:;" onclick="scrollToCenter();" title="定位到表格正中间" style ="color:white;">居中</a>
				                <a href="javascript:;" onclick="scrollToRight();" title="定位到表格最右端" style ="color:white;">最右</a>
							</h4>
							<span class="tools"> <a href="javascript:;"
								class="icon-chevron-down"></a>
							</span>
						</div>

						<div class="widget-body" style="overflow: auto" id="canvas-wrap">
							<div class="pageBottom" style="text-align: center;">
								<input type="hidden" id="page-size" value="0" />
								<div id="callBackPager" class="paging_bootstrap pagination"></div>
							</div>
							<table class="table table-striped table-hover table-bordered"
								width="640px;" style="table-layout: fixed">
								<thead>
									<tr>
										<th width="25px">修改</th>
										<th width="50px">费用类型</th>
										<th width="75px">二级费用类型</th>
										<th width="50px">申请金额</th>
										<th width="60px">省份</th>
										<th width="60px">客户</th>
										<th width="50px">入货乙方</th>
										<th width="50px">区县</th>
										<th width="30px">条线</th>
										<th width="54px">品规</th>
										<th width="50px">中标价</th>
										<th width="50px">开票价</th>
										<th width="50px">测算价</th>
										<th width="120px">返款总费用</th>
										<th width="150px">返款信息</th>
										<th width="70px">开始时间</th>
										<th width="70px">结束日期</th>
										<th width="70px">当前月均纯销</th>
										<th width="70px">目标月均纯销</th>
										<th width="150px">备注</th>
										<th width="50px">申请状态</th>
										<th width="40px">经理</th>
										<th width="40px">制单人</th>
									</tr>
								</thead>
								<tbody id="distribute-body">
								</tbody>
							</table>
						</div>
					</div>
					<!-- END ALERTS PORTLET-->
				</div>
			</div>
		</div>
		<!-- END BASIC PORTLET-->
	</div>


	<!-- BEGIN JAVASCRIPTS -->
	<!-- Load javascripts at bottom, this will reduce page load time -->
	<script src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.nicescroll.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js" type="text/javascript" ></script>
	<script src="${pageContext.request.contextPath}/js/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.easy-pie-chart.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.sparkline.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/Chart.js"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.scrollTo.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/common-scripts.js"></script>

	<!-- start layer -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
	<!-- end layer  -->

	<!-- start 多选下拉，并具备过滤功能 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap-multiselect.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-multiselect.css" type="text/css" />
	<!-- end 多选下拉，并具备过滤功能 -->

	<!-- start 自动补全 -->
	<script src="${pageContext.request.contextPath}/js/bootstrap-typeahead.js"></script>
	<!-- end 自动补全 -->

	<!-- start 分页插件 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/extendPagination.js"></script>
	<!-- end 分页插件 -->

	<!-- start 日期插件 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
	<!-- end 日期插件 -->


	<!-- 自定义的script方法 -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/javascript/httpService.js"></script>

	<!-- 复制 -->
	<script src="${pageContext.request.contextPath}/js/jquery.zclip.min.js" type="text/javascript" ></script>
	
	
	<!-- 查询条件相关 -->
	<script type="text/javascript">
		
		$(document).ready(function() {
			//自动补全 填写数据源
			//多选下拉，并具备过滤功能 填写数据源
			$('#stripLine').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择条线',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
			$('#costType').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择费用类型',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
			$('#status').multiselect({
				includeSelectAllOption : true,
				nonSelectedText : '请选择状态',
				enableFiltering : true,
				maxHeight : 300,
				buttonWidth : '100px'
			});
			$('#regulation').multiselect({
                includeSelectAllOption : true,
                nonSelectedText : '请选择品规',
                enableFiltering : true,
                maxHeight : 300,
                buttonWidth : '100px'
            });
		});
	</script>

	<!-- 查询显示list -->
	<script type="text/javascript">
		function query(pageNumber, pageSize) {
			//查询后，隐藏查询区域
			var url = "${pageContext.request.contextPath }/cost/selectForList.do?pageNumber="
					+ pageNumber + "&pageSize=" + pageSize;
			var params = $("#filterForm").serialize();
	    	queryList(url,params);
		}

		function checkStatus(id,type,status){
			var age = $("#age").val();
			if(status=='已备案' && age!=1){
				layer.msg("改条申请已完成OA备案！已不能进行操作！");
			}else{
				showOpen(id,type);
			}
		}
		//动态填充table 列表数据
		function createTable(currPage, limit, total, items) {
			var html = [], showNum = limit;
			if (total - (currPage * limit) < 0)
				showNum = total - ((currPage - 1) * limit);
			for (var i = 0; i < showNum; i++) {
				html.push("<tr ondblclick=\"checkStatus('" + items[i].id+ "','修改','" + items[i].status+ "')\" >");
				html.push('<td>' +
				"<i class=\"icon-edit\" onclick=\"checkStatus('" + items[i].id+ "','修改','" + items[i].status+ "')\"></i>"
						+ '</td>');
				html.push('<td>' + formatData(items[i].costType)+ '</td>');
				html.push('<td>' + formatData(items[i].costTypeTwo)+ '</td>');
				html.push('<td>' + formatData(items[i].money) + '</td>');
				html.push('<td>' + formatData(items[i].province) + '</td>');
				html.push('<td>' + formatData(items[i].customer) + '</td>');
				html.push('<td>' + formatData(items[i].terminal) + '</td>');
				html.push('<td>' + formatData(items[i].county) + '</td>');
				html.push('<td>' + formatData(items[i].stripLine)+ '</td>');
				html.push('<td>' + formatData(items[i].regulation) + '</td>');
				html.push('<td>' + formatData(items[i].zbPrice) +'</td>');
				html.push('<td>' + formatData(items[i].kpPrice) + '</td>');
				html.push('<td>' + formatData(items[i].csPrice) + '</td>');
				html.push('<td>' + formatData(items[i].totalCost) + '</td>');
				html.push('<td>' + formatData(items[i].refundsInfo) + '</td>');
				html.push('<td>' + formatDateYMD(items[i].startTime)+ '</td>');
				html.push('<td>' + formatDateYMD(items[i].endTime)+ '</td>');
				html.push('<td>' + formatData(items[i].nowMonthSale) + '</td>');
				html.push('<td>' + formatData(items[i].aimMonthSale) + '</td>');
				html.push('<td>' + formatData(items[i].remark) + '</td>');
				html.push('<td>' + formatData(items[i].status)+ '</td>');
				html.push('<td>' + formatData(items[i].mgr)+ '</td>');
				html.push('<td>' + formatData(items[i].dataer)+ '</td>');
				html.push('</tr>');
			}
			var mainObj = $('#distribute-body');
			mainObj.empty();
			mainObj.html(html.join(''));
		};
	</script>

	<!-- 新增、更新相关 -->
	<script>
		//件数定义
		var p400 = 400;
		var p300 = 300;
		var p200 = 200;
		var p320 = 320;
	    $("#form_div").find("#countyU").hide();
		var htmls = $("#form_div").html();
		var uploadFileHtml = $("#uploadFileForm").html();
		var ret = null;
		var action = null;
		var open = false;
		
		function changeTC(v){
			if(v=='入货乙方'){
				$("#countyU").hide();
				$("#terminalU").show();
				$("#countyU").val("");
			}else{
				$("#terminalU").hide();
				$("#terminalU").val("");
				$("#countyU").show();
			}
		}
		
		function checkByHobby(formId){
			//获取到session中的hobby
			
			<%-- var hobby = "<%=session.getAttribute("hobby")%>"; 
			
			var address = "null";
			if(hobby=='深圳发货岗'){
				noNull = $("#"+formId+"").find(".sz");
				address = "深圳";
			}else if(hobby=='新疆发货岗'){
				noNull = $("#"+formId+"").find(".xj");
				address = "新疆";
			}
			console.log(noNull); --%>
			var noNull = [];
			noNull = $("#"+formId+"").find(".noNull");
			for(var i=0;i<noNull.length;i++){
		        if(noNull[i].value==null||noNull[i].value==undefined||noNull[i].value==""){
		            layer.msg("存在未填写项，请完善！");
		            return "false";
		        }
		    }
			return "true";
		}
		
		var note="开始日期：";
		//type:新增、修改
		function showOpen(id, type) {
			$("#form_div").remove();
			//不管是新增还是修改，都要打开这个对话框
			layer.open({
				title : [ type + '【费用申请】', 'font-size:18px;' ],
				type : 1,
				content : htmls, //这里content是一个普通的String
				btn : [ '提交','取消' ],
				yes : function(index, layero) {
					var ret = checkByHobby("submitForm");
					if (ret == "false") {
						open = true;
						return open;
					}
					layer.load(2);
					if ("新增" == type) {
						action = "${pageContext.request.contextPath }/cost/costUiAU.do?flag=N";
					} else if ("修改" == type) {
						action = "${pageContext.request.contextPath }/cost/costUiAU.do?flag=E";
					}
					var age = $("#age").val();
					var params = $("#submitForm").serialize();
					sendRequest(action, params, function(result) {
						var code = result.code;
						var cost = result.msg;
						if (code == -2) { //excel校验不通过
							open = true;
							layer.msg(result.msg);
						} else if (code == -1) { // 有错误
							layer.alert(result.msg);
						} else if (code > 0) {
							note += formatDateYMD(cost.startTime)+"\n";
							note += "结束日期："+formatDateYMD(cost.endTime)+"\n";
							if(cost.costTypeTwo != null){
								note += "费用类型："+cost.costType+"-"+cost.costTypeTwo+"\n";
							} else {
								note += "费用类型："+cost.costType+"\n";
							}
							note += "申请金额："+cost.money+"\n";
							note += "客户："+cost.customer+"\n";
							note += "入货乙方/区县："+cost.terminal+"\n";
							note += "品规："+cost.regulation+"\n";
							note += "条线："+cost.stripLine+"\n";
							note += "中标价："+cost.zbPrice+"\n";
							note += "开票价："+cost.kpPrice+"\n";
							note += "测算价："+cost.csPrice+"\n";
							note += "返款总费用："+cost.totalCost+"\n";
							note += "返款信息："+cost.refundsInfo+"\n";
							note += "当前月均纯销："+cost.nowMonthSale+"\n";
							note += "目标月均纯销 ："+cost.aimMonthSale+"\n";
							note += "备注："+cost.remark;
							
							
							layer.closeAll();
							layer.alert("提交成功");
							
							var html = '<div class="modal-body" style="padding-left:10px;height: 90%">';
							html +="<table>";
							html +="<tr>";
							html +="<td>";
							html +='<textarea class="input-large" rows="20" cols="100"  name="note" id="noteU">'+note+'</textarea> ';
							html +="</td>";
							html +=" </tr>";
							html +=" </table>";
							html +=" </div>";
							
							layer.open({
								title : ['【微信申请费用模板信息】', 'font-size:18px;' ],
								type : 1,
								content : html, //这里content是一个普通的String
								btn : [ '关闭' ],
								cancel : function() {
								},
								area : [ '310px', '450px' ]
							//调整弹出框的长宽
							});
							query(pNumber, pSize);
						}
					});
					return open;
				},
				cancel : function() {
				},
				area : [ '310px', '450px' ]
			//调整弹出框的长宽
			});

			if ("修改" == type) {
				var url = "${pageContext.request.contextPath }/cost/selectByID.do";
				sendRequest(url,{"id" : id},function(result) {
					var code = result.code;
					var ret = result.msg;
					if (code > 0) {
						$("#mgrU").val(ret.mgr);
						$("#idU").val(ret.id);
						$("#costTypeU").val(ret.costType);
						$("#moneyU").val(ret.money);
						$("#customerU").val(ret.customer);
						$("#provinceU").val(ret.province);
						if(ret.terminal!=''){
							$("#terminalU").val(ret.terminal);
							$("#terminalU").show();
							$("#countyU").hide();
							$("#tc").val("入货乙方");
						}else{
							$("#countyU").val(ret.county);
							$("#countyU").show();
                            $("#terminalU").hide();
                            $("#tc").val("区县");
						}
						$("#stripLineU").val(ret.stripLine);
						$("#regulationU").val(ret.regulation);
						$("#zbPriceU").val(ret.zbPrice);
						$("#kpPriceU").val(ret.kpPrice);
						$("#csPriceU").val(ret.csPrice);
						$("#totalCostU").val(ret.totalCost);
						$("#refundsInfoU").val(ret.refundsInfo);
						$("#startTimeU").val(formatDateYMD(ret.startTime));
						$("#endTimeU").val(formatDateYMD(ret.endTime));
						$("#nowMonthSaleU").val(ret.nowMonthSale);
						$("#aimMonthSaleU").val(ret.aimMonthSale);
						$("#remarkU").val(ret.remark);
					}
				});
			}

			//给日期赋值默认值        
			/*var value = new Date().getFullYear()+'/'+(new Date().getMonth()+1) + '/' + new Date().getDate();
			$("#kaipiaoTimeU").val(value);   //开票日期
			$("#kaipiaoApplyTimeU").val(value);//开票申请日期
			$("#deliveryApplyTimeU").val(value);// 发货申请日期*/
			
			
			//自动补全 填充数据源
			var mgr = ${condiMap.mgr};
	        $('#mgr').typeahead({
	        	source: mgr
	        	})
	        $('#mgrU').typeahead({
	        	source: mgr
	        	})
	        var terminal = ${condiMap.terminal};
	        $('#terminalU').typeahead({
	        	source: terminal
	        	})
			var county = ${countyList};
			$('#countyU').typeahead({
				source : county
			});
			var clientList = ${clientList};
			$('#customerU').typeahead({
				source : clientList
			});
			var provinceList = ${provinceList};
			
			$('#provinceU').typeahead({
				source : provinceList
			});
			
		}

		//自动填充数量
		function fillCount() {
			//获取用户已经选择好的包装
			var product = $("#productU").val();
			var pack = $("#packU").val();
			var kaipiaojia = $("#kaipiaojiaU").val()
			var pcount = $("#pcountU").val();

			if (product == "A") {
				if (pack == "20" || pack == "30" || pack == "40"|| pack == "24") {
					$("#countU").val(p400 * pcount);
				} else if (pack == "36" || pack == "48") {
					$("#countU").val(p300 * pcount);
				} else {
					$("#countU").val("");
				}
			}
			if (product == "Y") {
				if (pack == "20" || pack == "40") {
					$("#countU").val(p200 * pcount);
				} else if (pack == "30" || pack == "24") {
					$("#countU").val(p400 * pcount);
				} else if (pack == "36") {
					$("#countU").val(p320 * pcount);
				} else {
					$("#countU").val("");
				}
			}
			if (product == "Z") {
				if (pack == "20" || pack == "30") {
					$("#countU").val(p300 * pcount);
				} else if (pack == "24") {
					$("#countU").val(p200 * pcount);
				} else if (pack == "48") {
					$("#countU").val(p400 * pcount);
				} else {
					$("#countU").val("");
				}
			}
		}
		//自动填充金额
		function fillMoney() {
			var kaipiaojia = parseFloat($("#kaipiaojiaU").val());
			var count = parseFloat($("#countU").val())
			if(kaipiaojia>=0 && count>=0){
				var money = kaipiaojia * count;
	            $("#moneyU").val(money.toFixed(2));
			}/*else{
				layer.msg("开票价和数量不能为0！！！");
			}*/
		}
		//自动填充开票备注
		function fillKaipiaoDemo() {
			var h = $("#hasHuopiaotongxingU").val();
			var ph = $("#piciU").val().split("/");
			if (h == "是") {
				var note = "货票同行、发票备注批号" + ph[0] + "、生产日期" + ph[0] + "及效期"+ ph[1];
			} else {
				var note = "暂不开发票，后期OA申请";
			}
			$("#kaipiaoDemoU").val(note);
		}
		
		//填充模板
		function fillmk() {
			$("#noteU").val(note);
		}
		
		//自动填充费用申请相关的数据
		function fill() {
			//加载层
			var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
			//loading层
			var index = layer.load(1, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
			});
			
			var params = $("#submitForm").serialize();
			var url = "${pageContext.request.contextPath }/policy/selectPolicy.do";
			sendRequest(url,params,function(result) {
				var code = result.code;
				var ret = result.msg;
				var code = result.code;
				if (code == -1) { // 有错误
					$("#zbPriceU").val("");
					$("#kpPriceU").val("");
					$("#csPriceU").val("");
					$("#refundsInfoU").val("");
					$("#totalCostU").val("");
					layer.alert(result.msg);
				} else if (code > 0) {
					$("#zbPriceU").val(ret.zhongbiaojia);
					$("#kpPriceU").val(ret.kaipiaojia);
					$("#csPriceU").val(ret.dijia);
					$("#refundsInfoU").val(ret.shoukuangren+"、"+ret.kaihuhang+"、"+ret.zhanghao);
					$("#totalCostU").val(ret.tuiguangmoney+"+"+ret.fapiaomoney+"+"+ret.daibiaomoney);
				}
			});
		}
		
		//日期格式化
		function formatDateYMD(time){
		    var date = new Date(time);
		    var year = date.getFullYear(),
		        month = date.getMonth() + 1,//月份是从0开始的
		        day = date.getDate();
		    var newTime = year + '/' +
		                month + '/' +
		                day;
		    return newTime;         
		}
		
		function checkDate() {
			var s_y = $("#startTimeU").val().substring(0,4);
			var s_m = $("#startTimeU").val().substring(4,6);
			var s_d = $("#startTimeU").val().substring(6,8);
			alert(s_y);
			alert(s_m);
			alert(s_d);
			var curTime = formatDateYMD(new Date());
			//alert(curTime);
		}
		
	</script>
	
</body>
</html>